package com.zhong.reflect;

import com.zhong.model.User;
import org.junit.Test;

import java.lang.reflect.Constructor;

/**
 * @author:yanglin on 2018/6/17.
 */
public class ClassDemo {

    //User
    @Test
    public void demo() throws Exception{
        //1.
        Class<? extends User> clazz1 = new User().getClass();
        
        //2.  推荐使用
        Class<User> clazz2 = User.class;
        
        //3.
        Class<?> clazz3 = Class.forName("com.zhong.model.User");

        System.err.println(clazz1);
        System.err.println(clazz2);
        System.err.println(clazz3);
        System.err.println(clazz2.getName());

        //JDBC
        //Class.forName("com.mysql.jdbc.Driver")
    }

    //
    @Test
    public void demo2() throws Exception{
        Class<User> clazz2 = User.class;

    //得到全路径
    String name = clazz2.getName();

    //构造方法
    Constructor<User> constructor = clazz2.getConstructor();

    //如何得到一个具体实例
    User user = clazz2.newInstance();

    //得到父类
    Class<? super User> superclass = clazz2.getSuperclass();
}
}
